package com.xnyzc.lhy.resource.controller.invoice;

import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.resource.entity.invoice.InvoiceAaOpenParam;
import com.xnyzc.lhy.resource.entity.invoice.InvoiceAaOpenResult;
import com.xnyzc.lhy.resource.entity.invoice.InvoiceAaQueryOrCancellationParam;
import com.xnyzc.lhy.resource.service.invoice.IInvoiceAaService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 电子发票接口(AA提供)
 * </p>
 *
 * @author 刘举
 * @since 2019-10-24
 */
@Slf4j
@RestController
@RequestMapping("/invoiceAa")
public class InvoiceAaController {

    @Autowired
    IInvoiceAaService iInvoiceAaService;


    /**
     * 发票开具(Aa)
     *
     * @param invoiceAaParam
     * @return
     */
    @ApiOperation(value = "发票开具", notes = "发票开具")
    @PostMapping(value = "/invoiceAaOpenRequest")
    public InvoiceAaOpenResult invoiceOpenRequest(@RequestBody InvoiceAaOpenParam invoiceAaParam) {
        InvoiceAaOpenResult invoiceAaOpenResult = new InvoiceAaOpenResult();
        if (CheckUtil.objIsEmpty(invoiceAaParam)) {
            log.info("发票开具失败,请求参数为null");
            return invoiceAaOpenResult;
        }
        // 调用开票接口
        try {
            invoiceAaOpenResult = iInvoiceAaService.invoiceAaOpenRequest(invoiceAaParam);
        } catch (Exception e) {
            log.info("发票开具异常，错误信息：{}", e);
        }
        return invoiceAaOpenResult;
    }

    /**
     * 发票状态查询(Aa)
     *
     * @param invoiceQueryParam
     * @return
     */
    @ApiOperation(value = "发票状态查询", notes = "发票状态查询")
    @PostMapping(value = "/getInvoiceAaQuery")
    public InvoiceAaOpenResult getInvoiceAaQuery(@RequestBody InvoiceAaQueryOrCancellationParam invoiceQueryParam) {
        InvoiceAaOpenResult invoiceAaOpenResult = new InvoiceAaOpenResult();
        if (CheckUtil.objIsEmpty(invoiceQueryParam)) {
            log.info("发票查询失败,请求参数为null");
            return invoiceAaOpenResult;
        }
        // 调用发票查询接口
        try {
            invoiceAaOpenResult = iInvoiceAaService.invoiceAaQueryRequest(invoiceQueryParam);
        } catch (Exception e) {
            log.info("发票开具异常，错误信息：{}", e);
        }
        return invoiceAaOpenResult;
    }

    /**
     * 发票冲红作废(Aa)
     *
     * @param invoiceCancellationParam
     * @return
     */
    @ApiOperation(value = "发票冲红作废", notes = "发票冲红作废")
    @PostMapping(value = "/invoiceAaCancellation")
    public InvoiceAaOpenResult invoiceAaCancellation(@RequestBody InvoiceAaQueryOrCancellationParam invoiceCancellationParam) {
        InvoiceAaOpenResult invoiceAaOpenResult = new InvoiceAaOpenResult();
        if (CheckUtil.objIsEmpty(invoiceCancellationParam)) {
            log.info("发票冲红失败,请求参数为null");
            return invoiceAaOpenResult;
        }
        // 调用发票查询接口
        try {
            invoiceAaOpenResult = iInvoiceAaService.invoiceAaCancellationRequest(invoiceCancellationParam);
        } catch (Exception e) {
            log.info("发票开具异常，错误信息：{}", e);
        }
        return invoiceAaOpenResult;
    }

}
